package leo.mystudy.check;

import leo.mystudy.utils.FileUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author lichao email:lichao@witspring.com
 * @Description: 检查文件
 * @Date 2018/4/26 11:09
 * @since Ver V0.0.1
 */
public class CheckFile {

    public static void main(String[] args) throws IOException {
        new CheckFile().checkTwoFileContains("C:\\Users\\leo_1\\Desktop\\TEST\\new_6.txt", "C:\\Users\\leo_1\\Desktop\\TEST\\old_6.txt");
    }

    /**
     * 判断file1是否包含file2中的内容
     *
     * @param file1
     * @param file2
     */
    public void checkTwoFileContains(String file1, String file2) throws IOException {
        List<String> list = FileUtil.getLines(file1);
        BufferedReader bufferedReader = FileUtil.getReader(file2);
        String line;
        Set<String> set = new HashSet<>(list);
        while ((line = bufferedReader.readLine()) != null) {
            if (!set.contains(line)) {
                System.out.println(line);
            }
        }
        bufferedReader.close();
    }
}
